import 'package:equatable/equatable.dart';
import 'package:backend.purchases/domain/entities/app_store_api/app_store_api_transaction_offer_type.dart';

class AppStoreApiTransactionOfferTypeDto extends Equatable {
  const AppStoreApiTransactionOfferTypeDto._internal({
    required this.offerTypeCode,
  });

  final int? offerTypeCode;

  @override
  List<Object?> get props {
    return [
      offerTypeCode,
    ];
  }

  factory AppStoreApiTransactionOfferTypeDto.fromCode(int? code) {
    return AppStoreApiTransactionOfferTypeDto._internal(
      offerTypeCode: code,
    );
  }

  AppStoreApiTransactionOfferType toEntity() {
    if (offerTypeCode == null) {
      return AppStoreApiTransactionOfferType.regular;
    }

    if (offerTypeCode == 1) {
      return AppStoreApiTransactionOfferType.introductory;
    }

    if (offerTypeCode == 2) {
      return AppStoreApiTransactionOfferType.promotional;
    }

    if (offerTypeCode == 3) {
      return AppStoreApiTransactionOfferType.subscriptionCode;
    }

    throw UnimplementedError();
  }
}
